package ru.ifmo.rybakov.muclumon;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
 * Revision is a single point in time with associated data. Associated
 * data may describe resources configuration or state right in that moment
 * of time. All statistic data stored in database is ordered by revisions. 
 * 
 * @author gleb.rybakov
 */
@Entity
@Table(name = "revision")
public class Revision {
	@Id
	@GeneratedValue
	private Integer id;

	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime timestamp;
	
	@Column(nullable = false)
	@Enumerated(EnumType.STRING)
	private RevisionType type;

	/**
	 * Returns the id
	 * @return The id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Sets the id value
	 * @param id The id to be set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Returns the date and time revision was created
	 * @return The timestamp
	 */
	public DateTime getTimestamp() {
		return timestamp;
	}

	/**
	 * Sets the date and time revision was created
	 * @param timestamp The timestamp to be set
	 */
	public void setTimestamp(DateTime timestamp) {
		this.timestamp = timestamp;
	}

	/**
	 * Returns the type
	 * @return The type
	 */
	public RevisionType getType() {
		return type;
	}
	
	/**
	 * Sets the type value
	 * @param type The type to be set
	 */
	public void setType(RevisionType type) {
		this.type = type;
	}

	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (id != null && obj instanceof Revision) {
			return id.equals(((Revision) obj).getId());
		}
		return super.equals(obj);
	}

	
}
